前面的是在ROS1-Noetic裝的,那是否可以在ROS2裝?好像可以.我主要是照這個網頁安裝的,我發覺dVRK在Ubuntu 20.04-ROS2-galactic比ROS1-noetic更容易安裝.
附註, ROS2-galactic的簡易安裝
# locale跟repository universe通常安裝Ubuntu已經是弄好的,不用再改 #ROS2 key sudo apt update && sudo apt install curl sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg #加入repository echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null #安裝 sudo apt update sudo apt upgrade sudo apt install ros-galactic-desktop
# ROS 1.0 Noetic or ROS 2.0 Galactic echo ROS 1.0 or ROS 2.0? 1=Noetic 2=Galactic read ROS if (($ROS==1));then source /opt/ros/noetic/setup.bash echo "Noetic" elif (($ROS==2));then source /opt/ros/galactic/setup.bash echo "Galactic" else echo "Non-ROS" fi
各開2個terminal分別執行,看ROS2是否安裝成功
ros2 run demo_nodes_cpp talker
ros2 run demo_nodes_py listener
不過安裝過程中出現錯誤,我搞了好久,安裝跟移除一堆程式相依,甚至於移除掉原本的ROS2-galactic,但最後是靠一個指令
sudo aptitude install -f ros-galactic-desktop # -f強迫修復
先把ROS2全部先救回來,再重頭安裝一次dVRK,結果就成功了.
裝完ROS2之後,再照網頁裝dVRK
#以下是dVRK安裝
sudo apt install python3-vcstool python3-colcon-common-extensions # for colcon相依程式
sudo apt install python3-pykdl # for the CRTK Python client library
sudo apt install libxml2-dev libraw1394-dev libncurses5-dev qtcreator swig sox espeak cmake-curses-gui cmake-qt-gui git subversion gfortran libcppunit-dev libqt5xmlpatterns5-dev libbluetooth-dev
sudo apt install ros-galactic-joint-state-publisher* ros-galactic-xacro #如果你的Ubuntu是22.04版本,請照網頁安裝
source /opt/ros/galactic/setup.bash
mkdir -p ~/ros2_ws/src
cd ~/ros2_ws/src
vcs import --input https://raw.githubusercontent.com/jhu-dvrk/dvrk_robot_ros2/main/dvrk.vcs --recursive
cd ~/ros2_ws
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release
#source ~/ros2_ws/install/setup.bash
之後會比較好玩,要開4個terminal分別執行
#terminal 1 開啟dVRK
source ~/ros2_ws/install/setup.bash
cd ~/ros2_ws/install/sawIntuitiveResearchKitAll/share/sawIntuitiveResearchKit
ros2 run dvrk_robot dvrk_console_json -j share/console/console-PSM1_KIN_SIMULATED.json
#terminal 2 開啟RViz
source ~/ros2_ws/install/setup.bash
ros2 run rviz2 rviz2 -d ~/ros2_ws/install/dvrk_model/share/dvrk_model/rviz/PSM1.rviz
#terminal 3 dVRK發佈到RViz
source ~/ros2_ws/install/setup.bash
ros2 launch dvrk_model dvrk_state_publisher.launch.py arm:=PSM1
#terminal 4 可以看到機器手臂在動 不過這是在網頁的terminal 2範例
source ~/ros2_ws/install/setup.bash
ros2 run dvrk_python dvrk_arm_test.py -a PSM1
附上螢幕錄影檔
你可以重複執行最後的指令,在dVRK視窗中,切換PSM1 PID跟PSM1,
你也可以嘗試其他在~/ros2_ws/src/dvrk/dvrk_python/scripts的python檔,例如
ros2 run dvrk_python dvrk_psm_test.py -a PSM1